package com.jzg.jcptadmin.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.app.ActivityHelp;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.constant.Constant;
import com.jzg.jcptadmin.data.vo.EstimateDetails;
import com.jzg.jcptadmin.data.vo.ValuationDetailData;
import com.jzg.jcptadmin.presenter.ValuationDetailPresenter;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.honorato.multistatetogglebutton.MultiStateToggleButton;
import org.honorato.multistatetogglebutton.ToggleButton;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wangyd on 15/12/29.
 * 估值结果界面
 */
public class ValuationDetailActivity extends BaseActivity implements View.OnClickListener {
    @Bind(R.id.title_content)
    TextView title_content;
    @Bind(R.id.title_return)
    ImageView title_return;
  /*  @Bind(R.id.title_history)
    ImageView title_history;*/

    @Bind(R.id.valuation_top_img)
    ImageView valuation_top_img;

    @Bind(R.id.valuation_car_fullname)
    TextView valuation_car_fullname;
    @Bind(R.id.valuation_car_cheling)
    TextView valuation_car_cheling;
    @Bind(R.id.valuation_car_mileage)
    TextView valuation_car_mileage;
    @Bind(R.id.valuation_car_city)
    TextView valuation_car_city;

    @Bind(R.id.buy_car_detail_pricegood)
    TextView buy_car_detail_pricegood;
    @Bind(R.id.buy_car_detail_pricenormal)
    TextView buy_car_detail_pricenormal;
    @Bind(R.id.buy_car_detail_pricebad)
    TextView buy_car_detail_pricebad;
    @Bind(R.id.buy_car_detail_pricecs)
    TextView buy_car_detail_pricecs;

    @Bind(R.id.mstb_multi_id)
    MultiStateToggleButton mstb_multi_id;

    private EstimateDetails estimateDetails;
    private String styleId;
    private ValuationDetailData datas;
    private String carId;
    private ValuationDetailPresenter valuationDetailPresenter;

//    @Bind(R.id.valuation_car_detail_barchart)
//    BarChart barChart1;
//
//    @Bind(R.id.valuation_car_detail_barchart_baozhi)
//    BarChart barChart2;

//    @Bind(R.id.circleratioview)
//    CircleRatioView circleRatioView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.valuation_detail);
        ButterKnife.bind(this);
       // styleId = getIntent().getStringExtra("id");//从vin查询结果页面传来
       // carId = getIntent().getStringExtra("carid");//从历史评估页面传来
        datas = getIntent().getParcelableExtra(ActivityHelp.ESTIMATEDETAILS);//从估值界面

      /*  if (styleId != null && datas == null) {
            valuationDetailPresenter = new ValuationDetailPresenter(DataManager.getInstance());
            valuationDetailPresenter.attachView(this);
            valuationDetailPresenter.ValuationDetailData(appContext.getUser().getUserId() + "", styleId, "");
        } else if (carId != null) {
            valuationDetailPresenter = new ValuationDetailPresenter(DataManager.getInstance());
            valuationDetailPresenter.attachView(this);
            valuationDetailPresenter.ValuationDetailData(appContext.getUser().getUserId() + "", "", carId);
        }*/


//        circleRatioView.setColors(new int[]{Color.RED, Color.RED, Color.RED, Color.RED, Color.RED});
//        showChartData();
//        showChartData1();
        if (datas != null) {
            initView();
        }

    }

    private void initView() {
        title_content.setText(R.string.valuation_result);
        ImageLoader.getInstance().displayImage(datas.getPicPath(), valuation_top_img);
        valuation_car_fullname.setText(datas.getFullName());
        valuation_car_cheling.setText(datas.getCarAge());
        valuation_car_mileage.setText(datas.getMileage());
        valuation_car_city.setText(datas.getCityName());
        buy_car_detail_pricegood.setText(datas.getC2BA() + "万");
        buy_car_detail_pricenormal.setText(datas.getC2BB() + "万");
        buy_car_detail_pricebad.setText(datas.getC2BC() + "万");
        buy_car_detail_pricecs.setText(datas.getNowMsrp() + "万");

        //默认选中第一个选项
        mstb_multi_id.setElements(R.array.planets_array, 0);
        mstb_multi_id.setColorRes(R.color.btn_blue, R.color.white);
        mstb_multi_id.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
            @Override
            public void onValueChanged(int value) {
                if (value == 0) {
                    buy_car_detail_pricegood.setText(datas.getC2BA() + "万");
                    buy_car_detail_pricenormal.setText(datas.getC2BB() + "万");
                    buy_car_detail_pricebad.setText(datas.getC2BC() + "万");
                    buy_car_detail_pricecs.setText(datas.getNowMsrp() + "万");
                } else {
                    buy_car_detail_pricegood.setText(datas.getB2CA() + "万");
                    buy_car_detail_pricenormal.setText(datas.getB2CB() + "万");
                    buy_car_detail_pricebad.setText(datas.getB2CC() + "万");
                    buy_car_detail_pricecs.setText(datas.getNowMsrp() + "万");
                }
            }
        });
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @OnClick({R.id.title_return})
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.title_return:
                finish();
                break;
            case R.id.title_history:
                toHistoryActivity();
                break;
        }
    }

    public void toHistoryActivity() {
        ActivityHelp.startActivity(this, HistoryActivity.class);
    }

   /* *//**
     * 显示估值结果
     *
     * @param datas
     *//*
    @Override
    public void showData(ValuationDetailData datas) {
        this.datas = datas;
        initView();
    }*/

//    /**
//     * 获取估值结果参数
//     *
//     * @return
//     */
//    @Override
//    public Map<String, String> getValuationDetailParams() {
//        Map<String, String> params = new HashMap<>();
//        params.put("tokenid", "6");
//        params.put("UserId", String.valueOf(appContext.getUser().getUserId()));
//        //从vin查询结果页传递（页面重用根据页面传递参数请求接口）
//        if (!TextUtils.isEmpty(styleId)) {
//            params.put("styleId", styleId);
//        }
//        //从历史评估页面传递（页面重用根据页面传递参数请求接口）
//        if (!TextUtils.isEmpty(carId)) {
//            params.put("carId", carId);
//        }
//        Map<String, Object> maps = new HashMap<>();
//        maps.putAll(params);
//        params.put("sign", MD5Utils.getMD5Sign(maps));
//        return params;
//    }

    @Override
    public void showError(String error) {
        Toast.makeText(this, Constant.errr_net, Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (valuationDetailPresenter != null)
            valuationDetailPresenter.detachView();

        ButterKnife.unbind(this);
    }

    //    private void showChartData() {
//
//        ArrayList<Float> mChartDataList = new ArrayList<Float>();
//        mChartDataList.add(Float.valueOf(2100));
//        mChartDataList.add(Float.valueOf(2100));
//        mChartDataList.add(Float.valueOf(2100));
//        int year = Calendar.getInstance().get(Calendar.YEAR);
//        ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
//        ArrayList<String> xVal = new ArrayList<String>();
//        xVal.add(year + 1 + "");
//        xVal.add(year + 2 + "");
//        xVal.add(year + 3 + "");
//
//        for (int i = 0; i < mChartDataList.size(); i++) {
//            yVals.add(new BarEntry((float) mChartDataList.get(i), i));
//        }
//        BarChartTools.createBarChart(barChart1, xVal, yVals);
//    }
//
//    private void showChartData1() {
//
//        ArrayList<Float> mChartDataList = new ArrayList<Float>();
//        mChartDataList.add(Float.valueOf(2100));
//        mChartDataList.add(Float.valueOf(2100));
//        mChartDataList.add(Float.valueOf(2100));
//        int year = Calendar.getInstance().get(Calendar.YEAR);
//        ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
//        ArrayList<String> xVal = new ArrayList<String>();
//        xVal.add(year + 1 + "");
//        xVal.add(year + 2 + "");
//        xVal.add(year + 3 + "");
//
//        for (int i = 0; i < mChartDataList.size(); i++) {
//            yVals.add(new BarEntry((float) mChartDataList.get(i), i));
//        }
//        BarChartTools.createBarChart(barChart2, xVal, yVals);
//    }
}
